Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

302
Views
deshabilitar elementos cuando valor = 1, habilitarlos cuando valor > 1

Usando javascript solo, estoy tratando de decir if cycn = 1 , deshabilite el elemento de entrada con id="prevdl"

if cycn > 1 , no deshabilite el elemento con id="prevdl" y, en ambos casos, obtenga una vista previa del valor de cycn en <p> con id="transit"

pero la condición después de if (cycn = 1) se ejecuta sin importar qué. Y el uno después de otro no se ve en absoluto.

HTML

 <label for="cyclecount">Cycle Count:</label> <input type="number" id="cyccnt" name="cyclecount" placeholder="Today's cycle number" min="1" max="6" autocomplete="off" value=""><br><br> <p id="transit"></p> <label for="previousdoseLevel">Previous Dose Level:</label> <input type="number" id="prevdl" name="previousdoseLevel" placeholder="Insert Previous Dose Level" autocomplete="off" value=""><br><br>

JavaScript

 var cyc = document.getElementById("cyccnt"); var cycn = Number(cyc.value); document.getElementById("cyccnt").oninput = function (e) { if (cycn = 1) { document.getElementById("prevdl").disabled = true; document.getElementById("transit").innerHTML = cycn; } else if (cycn >1) { document.getElementById("prevdl").disabled = false; document.getElementById("transit").innerHTML = cycn; } e.preventDefault(e); }

por favor ayuda y gracias de antemano.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

usar doble ==

 if (cycn == 1) { document.getElementById("prevdl").disabled = true; document.getElementById("transit").innerHTML = cycn; }

y tome el valor del evento en su lugar.

 document.getElementById("cyccnt").oninput = function (e) { e.preventDefault(); var value = e.target.value document.getElementById("transit").innerHTML = value; if (value && +value == 1) { document.getElementById("prevdl").disabled = true; } else { document.getElementById("prevdl").disabled = false; } }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!